var ocrGml = require("../../utils/ocrGml");
var utils = require("../../utils/utils");
var common = require("./common");
function ifInTaskDefault() {
  var ocrItem = ocrGml.captureExistOne(["金币收益", "现金收益", "去提现"]);
  return ocrItem;
}
var inTask = {
  run(ifInTask, config) {
    this.ifInTask = ifInTask || ifInTaskDefault;
    this.over();
    sleep(utils.getRandom(1, 1.5, 1000));
    this.sign();
    sleep(utils.getRandom(1, 1.5, 1000));
    if (this.ad()) {
      return;
    }
    sleep(utils.getRandom(1, 1.5, 1000));
    if (config && config.fromAward) {
    } else {
      this.award();
    }
  },
  //领取
  award() {
    var contents = ["领取"];
    var ocrItem = ocrGml.captureExistOne(contents, true);
    if (ocrItem) {
      utils.clickOcrItem(ocrItem);
      this.run(null, {
        fromAward: true,
      });
    }
  },
  over() {
    var contents = ["开心收下", "立即收下", "我知道了"];
    var ocrItem = ocrGml.captureExistOne(contents, true);
    if (ocrItem) {
      utils.clickOcrItem(ocrItem);
      sleep(utils.getRandom(2, 3, 1000));
      return;
    }
  },
  sign() {
    var contents = ["立即签到"];
    var ocrItem = ocrGml.captureExistOne(contents, true);
    if (ocrItem) {
      utils.clickOcrItem(ocrItem);
      sleep(utils.getRandom(2, 3, 1000));
    }
    var contents = ["直接领取"];
    var ocrItem = ocrGml.captureExistOne(contents, true);
    if (ocrItem) {
      utils.clickOcrItem(ocrItem);
      sleep(utils.getRandom(2, 3, 1000));
    }
    return;
  },
  ad() {
    var contents = ["看广告再", "看视频再", "看广告领", "看视频领"];
    var ocrItem = ocrGml.captureExistOne(contents, true);
    if (ocrItem) {
      utils.clickOcrItem(ocrItem);
      sleep(utils.getRandom(2, 3, 1000));
      common.ad.init(2, this.ifInTask);
      sleep(utils.getRandom(2, 3, 1000));
      this.run(null, {
        fromAd: true,
      });
      return true;
    }
  },
};

module.exports = inTask;
